package com.github.zhp.web.handler;

import com.github.zhp.GenerateStarter;
import com.github.zhp.startup.ConfigJson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;

/**
 * 处理代码生成
 */
public class CodeGenerateHandler implements Handler<RoutingContext> {
    @Override
    public void handle(RoutingContext event) {
        String bodyAsString = event.getBodyAsString();
        Gson gson = new GsonBuilder().create();
//        JsonObject confJsonObj = event.getBodyAsJson();
//        ConfigJson configJson = confJsonObj.mapTo(ConfigJson.class);
//        System.out.println(configJson.getAuthor());
        //开始生成
        ConfigJson configJson = gson.fromJson(bodyAsString, ConfigJson.class);
        GenerateStarter generateStarter = new GenerateStarter();
        generateStarter.setJsonConfig(configJson);
        generateStarter.start();
        event.response().end("success");
    }
}
